#include <iostream>
#include <memory>
using std::cout;
using std::endl;
using namespace std;
// 简单工厂设计模式
enum ProductType
{
    TypeA,
    TypeB,
    TypeC
};
class Product
{
public:
    virtual void show() = 0;
    virtual ~Product() {}
};
class ProductA : public Product
{
public:
    ProductA()
    {
        cout << "ProductA()" << endl;
    }
    void show() override
    {
        cout << "void ProductA::show()" << endl;
    }
    ~ProductA()
    {
        cout << "~ProductA()" << endl;
    }
};
class ProductB : public Product
{
public:
    ProductB()
    {
        cout << "ProductB()" << endl;
    }
    void show() override
    {
        cout << "void ProductB::show()" << endl;
    }
    ~ProductB()
    {
        cout << "~ProductB()" << endl;
    }
};
class ProductC : public Product
{
public:
    ProductC()
    {
        cout << "ProductC()" << endl;
    }
    void show() override
    {
        cout << "void ProductC::show()" << endl;
    }
    ~ProductC()
    {
        cout << "~ProductC()" << endl;
    }
};
class ProductFactory
{
public:
    static unique_ptr<Product> creatProduct(ProductType type)
    {
        switch (type)
        {
        case TypeA:
            return unique_ptr<Product>(new ProductA());
        case TypeB:
            return unique_ptr<Product>(new ProductB());
        case TypeC:
            return unique_ptr<Product>(new ProductC());
        default:
            return unique_ptr<Product>(nullptr);
        }
    }
};
void test()
{
    unique_ptr<Product> pa = ProductFactory::creatProduct(TypeA);
    unique_ptr<Product> pb = ProductFactory::creatProduct(TypeB);
    unique_ptr<Product> pc = ProductFactory::creatProduct(TypeC);
    pa->show();
    pb->show();
    pc->show();
}
int main()
{
    test();
    return 0;
}
